const baseTitle = import.meta.env.VITE_APP_TITLE

function setDocumentTitle(title: string) {
  document.title = title
}
export default function useDocumentTitle() {
  const setTitle = (title: string | undefined) => {
    if (title) setDocumentTitle(`${title} - ${baseTitle}`)
    else resetTitle()
  }

  const resetTitle = () => {
    setDocumentTitle(`${baseTitle}`)
  }

  return {
    setTitle,
    resetTitle
  }
}
